/**
 * @Title: AddTeacherModal.js
 * @Description: AddTeacherModal
 * @author: Fanchao
 * @date: 2020/12/18 9:51 下午
 * @version V1.0
 */
import React from "react";
import { Form, message, Modal, Select } from "antd";
import { addTaskExpert } from "api/index";
import { connect } from "umi";
const { Option } = Select;
const layout = {
    labelCol: { span: 4 },
    wrapperCol: { span: 20 }
};
const AddTeacherModal = ({ addModal, itemId, cb, task: { expertTeacherListOption }, dispatch }) => {
    const [form] = Form.useForm();
    return (
        <Modal
            title="添加专家"
            visible={addModal}
            width="600px"
            onOk={() => {
                form.validateFields().then(values => {
                    values.evaluateTaskId = itemId;
                    delete values.time;
                    addTaskExpert(values).then(res => {
                        if (res.status === "success") {
                            dispatch({
                                type: "task/getDataSource",
                                payload: {
                                    keyword: "",
                                    reqPageInfo: {
                                        pageNumber: 1,
                                        pageSize: 10
                                    }
                                }
                            });
                            form.resetFields();
                            cb && cb();
                        } else {
                            message.error(res.message);
                        }
                    });
                });
            }}
            onCancel={() => {
                form.resetFields();
                cb && cb();
            }}
        >
            <Form
                {...layout}
                layout="horizontal"
                form={form}
            >

                <Form.Item
                    label="督导专家"
                    name="teacherUserIds"
                    rules={[{ required: true, message: "必填" }]}
                >
                    <Select
                        mode="multiple"
                        placeholder="请选择督导专家"
                    >
                        {
                            expertTeacherListOption.map(item => {
                                return (
                                    <Option
                                        key={item.teacherUserId}
                                        value={item.teacherUserId}
                                    >
                                        {item.teacherRealName}
                                    </Option>
                                );
                            })
                        }
                    </Select>
                </Form.Item>
            </Form>
        </Modal>
    );
};

export default connect(({ task, dispatch }) => ({
    task,
    dispatch
}))(AddTeacherModal);
